const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getPrepInstructionsForSKU = {};
getPrepInstructionsForSKU.generateOption = function(seller_id, mws_auth_token, sellerSKUList, shipToCountryCode){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'GetPrepInstructionsForASIN',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'ShipToCountryCode': shipToCountryCode,
  };

  if (sellerSKUList) {
    let keyPrefix = "SellerSKUList.Id";
    sellerSKUList.forEach((item, index) => {
      baseOption[keyPrefix + "." + (index+1)] = item
    });
  }

  return baseOption;
};

getPrepInstructionsForSKU._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInboundShipment.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

getPrepInstructionsForSKU.getPrepInstructionsForSKU = function(seller_id, mws_auth_token, sellerSKUList, shipToCountryCode) {
  return this._(this.generateOption(seller_id, mws_auth_token, sellerSKUList, shipToCountryCode));
};

module.exports = getPrepInstructionsForSKU;